<template>
  <el-container class="home-container">
    <!-- 左侧菜单区 - 使用导入的 SideMenu 组件 -->
    <el-aside width="220px" class="system-aside">
      <SideMenu />
    </el-aside>

    <!-- 右侧内容区 -->
    <el-container>
      <!-- 顶部导航栏 -->
      <el-header class="system-header">
        <div class="header-right">
          <el-dropdown>
            <span class="user-info">
              <el-avatar :size="32" :src="userAvatar" />
              <span class="user-name">{{ username }}</span>
            </span>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item @click="logout">
                  <el-icon><SwitchButton /></el-icon>
                  退出登录
                </el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
        </div>
      </el-header>

      <!-- 内容区域 -->
      <el-main class="system-main">
        <router-view />
      </el-main>
    </el-container>
  </el-container>
</template>

<script setup>
import { computed } from 'vue'
import { useStore } from 'vuex'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { SwitchButton } from '@element-plus/icons-vue'
import SideMenu from '@/components/SideMenu.vue' // 导入菜单组件

const store = useStore()
const router = useRouter()

const username = computed(() => store.state.user.username || '管理员')
const userAvatar = computed(() => store.state.user.avatar || '@/assets/logo.png')

const logout = () => {
  store.dispatch('logout')
  router.push('/login')
  ElMessage.success('已退出登录')
}
</script>

<style scoped>
.home-container {
  height: 100vh;
}

/* 左侧菜单区样式 */
.system-aside {
  background-color: #001529;
  transition: width 0.3s;
}

/* 顶部导航栏样式 */
.system-header {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
}

.header-right {
  display: flex;
  align-items: center;
}

.user-info {
  display: flex;
  align-items: center;
  cursor: pointer;
}

.user-name {
  margin-left: 8px;
  font-size: 14px;
}

/* 内容区域样式 */
.system-main {
  background-color: #f5f7fa;
  padding: 20px;
  min-height: calc(100vh - 60px);
  overflow-y: auto;
}
.el-aside{
  overflow: hidden;
}
</style>